package com.awangyh.jdk8.map;

import com.awangyh.jdk8.file.NetValueItem;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: wangyanhui
 * @since: 2017/5/3
 */
public class EntityToMapDemo {

    public static void main(String ...strings) {
        List<NetValueItem> list = new ArrayList<NetValueItem>();
        NetValueItem item = new NetValueItem();
        item.setShortFilename("11254");
        item.setCode("1");
        list.add(item);

        item = new NetValueItem();
        item.setShortFilename("2222");
        item.setCode("2");
        list.add(item);

        item = new NetValueItem();
        item.setShortFilename("3333");
        item.setCode("3");
        list.add(item);

        Map<String, NetValueItem> map = list.stream().collect(Collectors.toMap(NetValueItem::getCode, it -> it));
        map.entrySet().forEach(entry -> {

            System.out.println("key: " + entry.getKey());
            System.out.println("value: " + entry.getValue().getShortFilename());
        });


    }
}
